package com.zmn.mcc.controller;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.mcc.common.dto.dept.DeptDRO;
import com.zmn.mcc.common.dto.permit.SpermitDTO;
import com.zmn.mcc.common.dto.staff.StaffDRO;
import com.zmn.mcc.common.dto.staff.StaffSimpleQueryDIO;
import com.zmn.mcc.dubbo.dto.DubboConsts;
import com.zmn.mcc.dubbo.interfaces.dept.DeptListRemoteService;
import com.zmn.mcc.dubbo.interfaces.organize.OrganizeListRemoteService;
import com.zmn.mcc.dubbo.interfaces.permit.PermitListRemoteService;
import com.zmn.mcc.dubbo.interfaces.role.RoleListRemoteService;
import com.zmn.mcc.dubbo.interfaces.staff.StaffListRemoteService;
import com.zmn.mcc.dubbo.interfaces.staff.StaffPermitRemoteService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.ibatis.annotations.Param;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * 类描述：
 *
 * @author liuyong
 * @since 2021/05/13 17:21
 */
@RestController
@RequestMapping("/test/dubbo/dept")
public class DeptTestController {

    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    private DeptListRemoteService deptListRemoteService;
    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    private StaffListRemoteService staffListRemoteService;
    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    private RoleListRemoteService roleListRemoteService;

    @DubboReference(version = DubboConsts.INTERFACE_VERSION, check = false)
    private StaffPermitRemoteService staffPermitRemoteService;

    @Resource
    private OrganizeListRemoteService organizeListRemoteService;

    @Resource
    private PermitListRemoteService permitListRemoteService;

    /**
     * 远程调用-取得指定部门顶级部门信息对象
     */
    @RequestMapping(value = "/getRootDept")
    public ResponseDTO getRootDept(@Param("deptId") Integer deptId) {

        ResponseDTO<DeptDRO> responseDTO = deptListRemoteService.getRootDept(deptId);
        return responseDTO;
    }


    @RequestMapping(value = "dubbo/listIncludeSubDept")
    public ResponseDTO listIncludeSubDept(HttpServletRequest request, Model model) {
        StaffSimpleQueryDIO dio = new StaffSimpleQueryDIO();
        dio.setDeptIds(Arrays.asList(4333));
        dio.setKeyword("郝传全");
        dio.setPlat(0);
        ResponseDTO<List<StaffDRO>> response = staffListRemoteService.listSubAllDeptStaffBySimpleQueryDIO(dio);
        return response;
    }

    @RequestMapping(value = "dubbo/listDpermitByStaffId")
    public SpermitDTO listDpermitByStaffId(Integer staffId, Integer dataType, Boolean clear) {

        return staffPermitRemoteService.listDpermitByStaffId(staffId, dataType, clear);
    }

    @RequestMapping(value = "dubbo/listVtByPlatsAndLevelAndParentIds")
    public ResponseDTO listVtByPlatsAndLevelAndParentIds(@RequestParam("plats")List<Integer> plats, Integer level, Integer status,@RequestParam("parentIdList") List<Integer> parentIdList){
        return organizeListRemoteService.listVtByPlatsAndLevelAndParentIds(plats, level, status, parentIdList);
    }

    @RequestMapping(value = "dubbo/listVtByPlatAndLevelAndParentIds")
    public ResponseDTO listVtByPlatsAndLevelAndParentIds(Integer plat, Integer level, Integer status,@RequestParam("parentIdList") List<Integer> parentIdList){
        return organizeListRemoteService.listVtByPlatAndLevelAndParentIds(plat, level, status, parentIdList);
    }

    /**
     * 从缓存中获取员工数据
     */
    @GetMapping(value = "/get/org")
    @ResponseBody
    public ResponseDTO getOrg() {

        return staffPermitRemoteService.listOrgPermitByStaffIdAndParentId(10003, 10);
    }

    @GetMapping(value = "/listOrgPermitByStaffId")
    @ResponseBody
    public ResponseDTO listOrgPermitByStaffId(Integer staffId) {

        return permitListRemoteService.listOrgPermitByStaffId(staffId);
    }

    @GetMapping(value = "/listRoleByStaffId")
    @ResponseBody
    public ResponseDTO listRoleByStaffId(Integer staffId){

       return roleListRemoteService.listRoleByStaffId(staffId);
    }

    @GetMapping(value = "/test111")
    @ResponseBody
    public ResponseDTO test111(Integer staffId){

        return staffListRemoteService.getSubStaffByLeaderId(staffId);
    }
}
